﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Proggy.Web.Cms.Controllers.FrontEnd;
using System.Web.Mvc;
using Proggy.Web.Cms.Core.ContentModels;
using System.IO;
using System.Web;

namespace Proggy.Web.Cms.Core.Controllers.ContentModel
{
    /// <summary>
    /// Controller for ProggyFileContentModel
    /// </summary>
    public class ProggyFileController : FrontEndControllerBase
    {
        public override ActionResult HandleUrl(int nodeId, bool asJson=false)
        {
            try
            {
                // get node
                var node = (ProggyFileContentModel)this.CurrentContentModel;
                    
                    //this.PublishedContentRepository.GetTypedContentSingleFromId<ProggyFileContentModel>(nodeId);

                //
                var stream = new FileStream(node.File.ServerFilePath, FileMode.Open);

                //
                return new FileStreamResult(stream, node.File.MimeType);
            }
            catch
            {
                throw new HttpException(404, "Page not found");
            }
        }
    }
}
